During the pandemic I started doing my math homework entirely in LaTeX, which can be a bit of a chore, so I decided to try to make it more fun by also making it look prettier using RMarkdown. I found that it makes it more intuitive for both the grader and unlucky homework doer. The additional tools that R has including graphing functions, and allowing calculations in console while typing lots and lots of LaTeX certainly increased my productivity while doing assignments. Using pagedown you can additionally print the html output of the rmd file to a pdf, even after adding themes (which are just added to make things more colorful, something math homework desperately needs). Below is a chunk that demonstrates how to do so:
knitr::opts_chunk$set(echo = TRUE)
library(pagedown)
setwd("/Users/dunk/Classes/MTH463/Homework 4")
pagedown::chrome_print(input = "Homework-4.html",
output = "Homework4.pdf")Each problem below is written using “$$ $$” as the wrappers, and “\begin{aligned} and \end{aligned}” to write the body of contiguous proofs, while additional information can be written in between, above, or below wrappers to easily differentiate parts of proofs. After creating a body with the format
$$
\begin{aligned}
\end{aligned}
$$all one has to do is add an & symbol with however you would like things aligned, and “\\” whenever a new line should be started like so:
$$
\begin{aligned}
\frac{d}{dx}e^{2x}&=\boxed{?} \\
&= \boxed{2e^{2x}}
\end{aligned}
$$should give
\[ \begin{aligned} \frac{d}{dx}e^{2x}&=\boxed{?} \\ &= \boxed{2e^{2x}} \end{aligned} \]
After that its just a question of LaTeX skills mixed with R and markdown, which opens up many more mathematical and visualization possibilities 😄.
The YAML to generate the html formatting for this document along with several other themes is pretty simple too:
---
title: 'Homework #X'
author: "Name Here"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
prettydoc::html_pretty:
theme: leonids # Other options are cayman, tactile, architect, leonids, hpstr
highlight: vignette
math: katex #Instead of mathjax so it works offline
documentclass: book
classoption:
- twocolumn
- landscape
papersize: a5
linestretch: 1.5
fontsize: 12pt
links-as-notes: true
header-includes:
- \usepackage{indentfirst}
---One of my own example homeworks from MTH 463 at Oregon State University is included below for reference.
Problem 1
I check that f(x) is a probability density function by finding if the cumulative distribution function is 1
\[ \begin{aligned} \int_{-\infty}^{\infty}f(x)dx&=\int_{-2}^{\infty}\frac{8dx}{x^3} \\ &=\Bigg[\frac{8x^{-2}}{-2}\Bigg]_{2}^{\infty} \\ &= \boxed{1} \end{aligned} \] So we know that f(x) is indeed a probability density function.
To find \(P(X>5)\)
\[ \begin{aligned} P(X>5)&=\int_{5}^{\infty}\frac{8dx}{x^3} \\ &= \Bigg[\frac{8x^{-2}}{-2}\Bigg]_{5}^{\infty} \\ &= \boxed{\frac{4}{25}} \end{aligned} \]
To find \(E[X]\) we use
\[ \begin{aligned} E[X]&=\int_{-\infty}^{\infty}xf(x)dx \\ &=\int_{2}^{\infty}\frac{8dx}{x^2} \\ &=\Bigg[\frac{8x^{-1}}{-1}\Bigg]_{2}^{\infty} \\ &=\boxed{4} \end{aligned} \]
Problem 2
I find c by integrating knowing the probability density function is equal to 1
\[ \begin{aligned} 1&=\int_{-\infty}^{\infty}f(x)dx \\ &= \int_{1}^{2}c(x-1)^4dx \\ &= \Bigg[\int_{1}^{2}\frac{c(x-1)^5}{5}\Bigg]_1^2 \\ &=\frac{c}{5} \\ \text{therefore, } &\boxed{ c=5} \end{aligned} \]
To find \(E[X]\) we have
\[ \begin{aligned} E[X]&=\int_{-\infty}^{\infty}xf(x)dx \\ &=\int_{1}^{2}5x(x-1)^4dx \\ &=\int_{1}^{2}5((x-1)+1)(x-1)^4dx \\ &=\int_{1}^{2}5(x-1)^5dx+\int_{1}^{2}5(x-1)^4dx \\ &=\Bigg[\frac{5(x-1)^6}{6}\Bigg]_1^2+1 \\ &= \frac{5}{6}+1 \\ &= \boxed{\frac{11}{6}} \end{aligned} \]
Problem 3
\[ \begin{aligned} 1&= \int_{-\infty}^{\infty}f(x)dx \\ &= \int_0^1(ax^2+bx)dx \\ &= \Bigg[ax^3\frac{1}{3}+bx^2\frac{1}{2}\Bigg] \\ &= \frac{1}{3}a+\frac{1}{2}b \end{aligned} \]
\[ \begin{aligned} 0.75&=E(X) \\ &=\int_{-\infty}^{\infty}xf(x)dx \\ &=\int_{0}^{1}(ax^3+bx^2)dx \\ &= \Bigg[a\frac{x^4}{4}+b\frac{x^3}{3}\Bigg]^1_0 \\ &=\frac{1}{4}a+\frac{1}{3}b \end{aligned} \]
So we have \(1 = \frac{1}{3}a+\frac{1}{2}b\) and \(0.75= \frac{1}{4}a+\frac{1}{3}b\) which reduces to \(b=0, a = 3\).
Therefore,
\[ \begin{aligned} E(X^2)&=\int_{-\infty}^{\infty}x^2f(x)dx \\ &=\int_{1}^{0}3x^4dx \\ &= \frac{3x^5}{5}\Bigg|_0^1 \\ &= \boxed{\frac{3}{5}} \end{aligned} \]
and,
\[ \begin{aligned} Var(X)&= E(X^2)-E(X)^2 \\ &= \frac{3}{5} - {0.75}^2 \\ &= \boxed{0.0375} \end{aligned} \]
Problem 4
\[ \begin{aligned} P(1<X<3)&=\int_1^3F(x)dx \\ &=\int_{-\infty}^3F(x)dx- \int_{-\infty}^1F(x)dx \\ &=F(3)-F(1) \\ &= \frac{15}{6}-\frac{3}{4} \\ &= \boxed{\frac{3}{16}} \end{aligned} \]
Problem 5
Given \(4x^2+4xY-Y+6=0\) with \(\lambda=3\), the roots of Y (\(\frac{-4Y \pm \sqrt{16Y^2+16(Y-6)}}{8}\)) will only be positive iff \(16Y^2+16(Y-6) \ge 0\). So we need to find
\[ \begin{aligned} P(16Y^2+16(Y-6) \ge 0)&=P(Y^2+Y-6 \ge 0) \\ &=P((Y+3)*(Y-2) \ge 0) \\ &=P(Y \le -3) + P(Y \ge 2) \\ &=0+e^{-2\lambda} \\ &= \boxed{e^{-6}} \end{aligned} \]
Problem 6
\[ \begin{aligned} \tau(\alpha + 1)&=\int_0^{\infty}e^{-y}y^{\alpha}dy \\ &= \int_0^{\infty}(-e^{-y})'y^{\alpha}dy \\ &=(-e^{-y}y^\alpha)\Bigg|_0^{\infty}-\int_0^{\infty}e^{-y}(y^{\alpha})'dy \\ &=0 + \int_0^{\infty}e^{-y}y^{\alpha-1}dy \\ &=\alpha \tau(\alpha) \\ \tau(1)&=\int_0^{\infty}e^{-y}dy \\ &=1=0! \end{aligned} \]
Therefore \(\tau(2)=1*\tau(1)=1!\)
Problem 7
\[ \begin{aligned} E[X^k]&=\int_0^{\infty}(\frac{y}{\lambda})^ke^{-y}dy \\ &=\frac{1}{\lambda^k}\int_0^{\infty}e^{-y}y^{(k+1)-1}dy \\ &=\frac{\tau(k+1)}{\lambda^k} \\ &=\frac{k!}{\lambda^k} \end{aligned} \]
Problem 8
\[ \begin{aligned} E[e^{-x}]&=\frac{1}{\tau(\alpha)}\int_0^{\infty}\lambda e^{-x}e^{-\lambda x}(\lambda x)^{\alpha -1}dx \\ &=\frac{\lambda}{\tau(\alpha)}\int_0^{\infty}e^{-(\lambda + 1) x}(x)^{\alpha -1}dx && \text{Let } y = (\lambda + 1)x \\ &=\frac{\lambda}{\tau(\alpha)}\int_0^{\infty}e^{-y}\frac{y^{\alpha - 1}}{(\lambda + 1)^{\alpha - 1}}\frac{1}{\lambda + 1}dy \\ &=\Bigg(\frac{\lambda}{\lambda+1}\Bigg)^\alpha\frac{1}{\tau(\alpha)}\int_0^{\infty}e^{-y}y^{\alpha-1}dy \\ &=\Bigg(\frac{\lambda}{\lambda+1}\Bigg)^\alpha \end{aligned} \]
Problem 9
We have \(t>0\), \(f(t)=\lambda e^{-\lambda t}\), \(F(t)=1-e^{-\lambda t}\).
\[ \begin{aligned} h(t)&=\frac{f(t)}{1-F(t)} \\ &=\frac{\lambda e^{-\lambda t}}{1-(1-e^{-\lambda t})} \\ &= \lambda \end{aligned} \]
The memorylessness property therefore makes it such that the “hazard rate” is constant at all times